﻿// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "custom/splitalpha2/footprint" {
    Properties {
        _MainTex ("Texture", 2D) = "white" { }
        _Color ("Tint", Color) = (1,1,1,1)
        [Toggle] _Horizontal("Horizontal", Float) = 0
    }
    SubShader {
		
		Tags
		{
			"Queue"="Transparent" 
			"IgnoreProjector"="True" 
			"RenderType"="Transparent" 
			"PreviewType"="Plane"
			"CanUseSpriteAtlas"="True"
		}

        Pass {
			Cull Off
			Lighting Off
			ZWrite Off
			Fog { Mode Off }
			Blend SrcAlpha OneMinusSrcAlpha
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			#include "UnityCG.cginc"

			sampler2D _MainTex;
			bool _Horizontal;
			fixed4 _Color;

			struct appdata_t
			{
				float4 vertex   : POSITION;
				float4 color    : COLOR;
				float2 texcoord : TEXCOORD0;
				float2 texcoord1: TEXCOORD1;
			};

			struct v2f
			{
				float4 vertex   : SV_POSITION;
				fixed4 color    : COLOR;
				float2 texcoord : TEXCOORD0;
				float2 texcoord1: TEXCOORD1;
			};
			
			float4 _MainTex_ST;

			v2f vert (appdata_t v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos (v.vertex);
				o.texcoord = v.texcoord;
				o.texcoord1 = v.texcoord1;
				o.color = v.color * _Color;
				return o;
			}

			fixed4 frag (v2f i) : SV_Target
			{
				float offset = fmod(i.texcoord1[0] * _Time.y, 1);
				i.texcoord[1] = fmod(i.texcoord[1] + offset + 1, 1.0);
				i.texcoord = TRANSFORM_TEX (i.texcoord, _MainTex);
				fixed4 texcol = tex2D (_MainTex, i.texcoord);
				half2 alphaTexCoord = i.texcoord;
				if(_Horizontal)
				{
					alphaTexCoord.x += 0.5f;
				}
				else
				{
					alphaTexCoord.y += 0.5f;
				}
				fixed4 alpha = tex2D(_MainTex, alphaTexCoord);
				texcol.a = alpha.r;
				texcol = texcol * i.color;
				return texcol;
			}
			ENDCG

        }
    }
}